import Vue from 'vue'
import VueRouter from 'vue-router'
import discovery from "../views/discovery";
import newmv from "../views/newmv";
import userinfo from "../views/userinfo";
import recommendMusicList from "../views/recommendMusicList";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:'/discovery'
  },
  {
    //发现音乐
    path: '/discovery',
    name:'discovery',
    component: discovery
  },
  {
    //推荐歌单
    path: '/recommendMusicList',
    name:'recommendMusicList',
    component: recommendMusicList
  },
  {
    //用户信息
    path: '/userinfo',
    name:'userinfo',
    component: userinfo
  },
  {
    //最新mv
    path: '/newmv',
    name:'newmv',
    component: newmv
  },
  {
    //歌单详情
    path: '/playlist/:id',
    name: 'playlist',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import( '../views/playlist.vue')
  },
  {
    //搜索结果页面
    path:'/result/:id',
    name:'result',
    component: () => import( '../views/result')
  },
  {
    //搜索结果页面
    path:'/collection',
    name:'collection',
    component: () => import( '../views/collection')
  },
  {
    //MV详情
    path: '/mvDetail',
    name: 'mvDetail',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import( '../views/mvDetail.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 给路由添加路由守卫在进行跳转时判断是否满足条件
// router.beforeEach((to,from,next)=>{
//   if (to.path === '/login') return next()
//   const token=vuex.state.token
//   if(!token) return next('/login')
//   next()
//
// })

export default router
